package com.ruanyin.web.servlet;

import com.ruanyin.service.UserService;
import com.ruanyin.service.impl.UserServiceImpl;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet("/deleteUserServlet")
public class DeleteUserServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // get id
        String id = request.getParameter("id");

        // delete user by id
        UserService service = new UserServiceImpl();
        service.deleteUserById(id);

        // foward to userListServlet
        request.getRequestDispatcher("/userListServlet").forward(request, response);
    }
}
